package br.com.merks.controller;

import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.merks.model.Category;
import br.com.merks.service.CategoryService;

@Resource
public class CategoriesController {
	private Result result = null;
	private CategoryService categoryService = null;
	public CategoriesController(CategoryService categoryService, Result result) {
		this.result = result;
		this.categoryService = categoryService;
	}
	@Path("/categories/form")
	public void form() {
		this.result.include("categories",this.categoryService.list());
	}
	@Path("/categories/drop/{category.id}")
	public void drop(Category category) {
		this.categoryService.delete(category);
		this.result.include("categories",this.categoryService.list());
	}
	@Post
	@Path("/categories/add")
	public void add(Category category) {
		this.categoryService.add(category);
		this.result.include("categories",this.categoryService.list());
	}
}
